<template>
  <div>
    <el-form ref="form" :model="form" label-width="120px" class="itemForm">
      <el-form-item label="用户ID">
        <el-input v-model="form.uid" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="find">查询</el-button>
        <el-button type="primary" @click="save">更新</el-button>
        <el-button type="danger" @click="del">删除</el-button>
      </el-form-item>

      <el-form-item label="体力">
        <el-input v-model="form.energy"/>
      </el-form-item>

      <el-form-item label="水量">
        <el-input v-model="form.water"/>
      </el-form-item>

      <el-form-item label="肥料">
        <el-input v-model="form.fertilizer"/>
      </el-form-item>

      <el-form-item label="农药">
        <el-input v-model="form.pesticide"/>
      </el-form-item>

      <el-form-item label="刚获取的果实">
        <el-input v-model="form.addFruit"/>
      </el-form-item>

      <el-form-item label="果实总量">
        <el-input v-model="form.fruit"/>
      </el-form-item>

      <el-form-item label="树">
        <el-input v-model="form.tree"/>
      </el-form-item>

      <el-form-item label="prop">
        <el-input v-model="form.prop"/>
      </el-form-item>

      <el-form-item label="每日事件">
        <el-input v-model="form.dailyEvent"/>
      </el-form-item>

      <el-form-item label="分享分数">
        <el-input v-model="form.shareScore"/>
      </el-form-item>

      <el-form-item label="碎片">
        <el-input v-model="form.jigsaws"/>
      </el-form-item>

      <el-form-item label="昨日浇水量">
        <el-input v-model="form.lastStorageWater"/>
      </el-form-item>

      <el-form-item label="今日浇水量">
        <el-input v-model="form.todayStorageWater"/>
      </el-form-item>

      <el-form-item label="动态">
        <el-input v-model="form.msg"/>
      </el-form-item>

      <el-form-item label="成语等级">
        <el-input v-model="form.lvl"/>
      </el-form-item>

      <el-form-item label="成语关卡解锁状态">
        <el-switch v-model="form.openLvl" disabled/>
      </el-form-item>

      <el-form-item label="成语提示">
        <el-input v-model="form.tipCnt"/>
      </el-form-item>

      <el-form-item label="自适应 关卡段位">
        <el-input v-model="form.autoLvlGrade" disabled/>
      </el-form-item>

      <el-form-item label="自适应 当前关卡难度">
        <el-input v-model="form.autoLvlDiff" disabled/>
      </el-form-item>

      <el-form-item label="自适应 当前关卡配置">
        <el-input v-model="form.autoLvlConf" type="textarea" autosize disabled/>
      </el-form-item>

      <el-form-item label="用户名">
        <el-input v-model="form.name" disabled/>
      </el-form-item>

      <el-form-item label="用户openId">
        <el-input v-model="form.openId" disabled/>
      </el-form-item>

      <el-form-item label="用户头像">
        <el-input v-model="form.headImg" disabled/>
      </el-form-item>

      <el-form-item label="邀请上级">
        <el-input v-model="form.inviteUid" disabled/>
      </el-form-item>

      <el-form-item label="详细数据">
        <json-view :data="form"/>
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
import { userInfo, updateUser, delAccount } from '@/api/player'
import jsonView from 'vue-json-views'

export default {
  name: 'Level',
  components: {
    jsonView
  },
  data() {
    return {
      form: {
        uid: 0,
        name: '',
        openId: '',
        isAuth: false,
        headImg: '',
        lvl: 0,
        openLvl: false,
        inviteUid: 0,
        energy: 0,
        shareScore: 0,
        water: 0,
        fertilizer: 0,
        pesticide: 0,
        fruit: '',
        addFruit: '',
        tree: '',
        dailyEvent: '',
        msg: '',
        lastUEnergyT: 0,
        diamond: 0,
        tipCnt: 0,
        autoLvlGrade: 0,
        autoLvlDiff: 0,
        stat: '',
        version: '',
        lastStorageWater: 0,
        todayStorageWater: 0,
        jigsaws: []
      }
    }
  },
  methods: {

    find() {
      console.log(this.form.uid)
      userInfo({
        uid: this.form.uid
      }).then(response => {
        console.log(response)
        this.form = response.data.player
        this.form.dailyEvent = response.data.dailyEvent
        this.form.jigsaws = response.data.jigsaws
        this.form.lastStorageWater = response.data.lastStorageWater
        this.form.todayStorageWater = response.data.todayStorageWater
        this.$forceUpdate()
        this.$message({ message: '更新数据成功！', type: 'success' })
      })
    },

    save() {
      updateUser({
        uid: this.form.uid,
        level: this.form.lvl,
        energy: this.form.energy,
        water: this.form.water,
        fertilizer: this.form.fertilizer,
        pesticide: this.form.pesticide,
        fruit: this.form.fruit,
        addFruit: this.form.addFruit,
        tree: this.form.tree,
        dailyEvent: this.form.dailyEvent,
        msg: this.form.msg,
        tipCnt: this.form.tipCnt,
        diamond: this.form.diamond,
        jigsaws: this.form.jigsaws,
        shareScore: this.form.shareScore,
        prop: this.form.prop,
        lastStorageWater: this.form.lastStorageWater,
        todayStorageWater: this.form.todayStorageWater
      }).then(response => {
        // this.$message({ message: '修改成功！', type: 'success' })
        this.find()
      })
    },

    del() {
      delAccount({
        uid: this.form.uid
      }).then(response => {
        this.$message({ message: '删除成功！', type: 'success' })
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.itemForm {
  margin: 30px;
  width: 800px;
}

.allItems {
  width: 800px;
  height: 48px;
}

.items {
  margin: 20px;
}

.item {
  float: left;
  margin: 2px;
}

.item-content {
  display: block;
  width: 16px;
  height: 16px;
}

.none {
  border: 1px solid #ebeef5;
}

.show {
  background-color: burlywood;
}

.hide {
  background-color: burlywood;
}

.text {
  font-size: 14px;
}

.itemIdiom {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  margin-left: 30px;
  width: 480px;
}
</style>
